package com.runda.biz.service;

import java.util.List;

import javax.annotation.Resource;

import com.bbjob.model.ProductAdapterInfo;
import com.bbjob.model.ProductQuotationRecord;
import com.bbjob.model.Production;
import com.bbjob.model.ProductionCodes;
import com.bbjob.util.service.impl.BaseService;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

@Service
public class ProductionService extends BaseService<Production> implements IProductionService{
    @Resource
    private ProductQuotationRecordService quotationService;
    @Resource
    private ProductionCodesService codesService;
    @Resource
    private ProductionAdaptionInfoService adaptionInfoService;
    
    public List<Production> getList(String typeCode,String query){
        Example example = new Example(Production.class);
        Criteria c=example.createCriteria();
        if(StringUtils.isNotBlank(typeCode)){
            c.andEqualTo("typeCode", typeCode);
        }
        if(StringUtils.isNotBlank(query)){
            c.andLike("hengAnNo", query+"%");
            Criteria oeC=example.createCriteria();
            oeC.andLike("oe", query+"%");
            Criteria nissens=example.createCriteria();
            nissens.andLike("nissens", query+"%");
            Criteria spi=example.createCriteria();
            spi.andLike("spi", query+"%");
            Criteria dpi=example.createCriteria();
            dpi.andLike("dpi", query+"%");
            example.or(oeC);
            example.or(nissens);
            example.or(spi);
            example.or(dpi);
        }   
        return this.mapper.selectByExample(example);   
    }
    @Override
    public int delete(Object key) {
        this.adaptionInfoService.deleteByProperty("productId", key, ProductAdapterInfo.class);
        this.codesService.deleteByProperty("productId", key, ProductionCodes.class);
        this.quotationService.deleteByProperty("productId", key, ProductQuotationRecord.class);
        return super.delete(key);
    }
}